package com.woniu.service.impl;

import com.woniu.mapper.DeptMapper;
import com.woniu.pojo.Dept;
import com.woniu.pojo.DeptExample;
import com.woniu.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class DeptServiceImpl implements DeptService {
    @Autowired
    DeptMapper deptMapper;
    @Override
    public List<Dept> getDeptList() {
        return deptMapper.selectByExample(null);
    }

    @Override
    public void saveDept(Dept dept) {
        deptMapper.insert(dept);
    }

    @Override
    public void deleteDept(Integer deptno) {
        deptMapper.deleteByPrimaryKey(deptno);

    }

    @Override
    public void updateDept(Dept dept) {
        deptMapper.updateByPrimaryKey(dept);
    }

    @Override
    public Dept getOneDept(Integer deptno) {
        return deptMapper.selectByPrimaryKey(deptno);
    }

    @Override
    public List<Dept> getDeptSelect(Dept dept) {
        DeptExample deptExample=new DeptExample();
        DeptExample.Criteria  criteria=deptExample.createCriteria();
        if(dept.getDname()!=null&&!dept.getDname().equals("")){
            criteria.andDnameLike("%"+dept.getDname()+"%");
        }
        if ((dept.getLoc()!=null&&!dept.getLoc().equals(""))){
            criteria.andLocLike("%"+dept.getLoc()+"%");
        }
        return deptMapper.selectByExample(deptExample);
    }

}
